//
//  HistoryBespeakVc.swift
//  Venus
//
//  Created by apple on 2018/9/3.
//  Copyright © 2018年 zhaowang. All rights reserved.
//  机构预约 - 历史预约

import UIKit


import UIKit
private let cellID = "LatestBespeakTvCell"
class HistoryBespeakVc: BaseViewController {
    
    /// 数据源
    var dataArr : [BespeakStruct] = []
    
    fileprivate lazy var tableView : UITableView = {
        let tableView = UITableView.init(frame: CGRect.zero, style: .plain)
        tableView.delegate = self
        tableView.dataSource = self
        tableView.separatorStyle = .none
        tableView.register(LatestBespeakTvCell.self, forCellReuseIdentifier: cellID)
        return tableView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
        loadData()
    }
    
}
extension HistoryBespeakVc {
    
    func loadData()  {
        //true查询所有已
        let userModel = UserInfo.shareInstance.userModel()
        
        let dict:String = [
            "id":String(userModel.institutionId),
            "isSee":"false" ,//true查询所有已确认过的预约单
            "pageNo":"1",
            "pageSize":"10",
            "sign":"1",
            "timestamp":"1",
            "operatorId":"79"
            ].formatApi()
        let url = kHost + kqueryAppointmentList + dict
        
        TempNetTool.post(url , parameters: nil, progress: nil, success: { [weak self] (result) in
            
            
        }) {[weak self] (error) in
            
        }
    }
}

// MARK: - LatestBespeakTvCellDelegate：cell的点击代理
extension HistoryBespeakVc:LatestBespeakTvCellDelegate{
    
    func clickCellPhone(row: Int) {
       // DDLOG(message: "点了手机按钮\(row) = \(self.dataArr[row].phone)")
    }
    
    func clickCellRecord(row: Int) {
       // DDLOG(message: "点了记录按钮\(row) = \(self.dataArr[row].remark)")
    }
}

// MARK:- 代理
extension HistoryBespeakVc:UITableViewDelegate , UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataArr.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView .dequeueReusableCell(withIdentifier: cellID, for: indexPath) as! LatestBespeakTvCell
        cell.configData(indexpath: indexPath, delegate: self, data: dataArr[indexPath.row])
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
    }
    
    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
    }
}

extension HistoryBespeakVc{
    func setupUI() {
        
        view.addSubview(tableView)
        tableView.snp.makeConstraints { (make) in
            make.left.right.equalTo(view)
            make.top.left.right.equalTo(view)
            if #available(iOS 11.0, *) {
                make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
            } else {
                make.bottom.equalTo(view.snp.bottom)
            }
        }
    }
}
